import config from "../config.js"
class http {
	// 外部调用
	request({url, data={}, method='GET'}){
        return new Promise((resolve, reject)=>{
            this._request(url, resolve, reject,data, method)
		})
	}
	_request({url, resolve, reject,data={}, method='GET'}) {
	
		request({
			url: config.api_base_url + url,
			method: method,
			data: data,
			header:{
				'content-type':'application/json',
				'appkey':config.appkey
			},
			success(res){
				let code = res.statusCode.toString()
				if(code.startsWith('2')){
					resolve(res.data)
				}else{
					reject()
				}
			},
			fail(err){
				reject()
			}
		})
	}
	
}

export {http}